package Game.Spawners;

import java.util.ArrayList;
import java.util.List;

import org.newdawn.slick.SlickException;

import Game.Level;
import Game.Objects.GOAltar;
import Game.Objects.GOBarrel;
import Game.Objects.GOChest;
import Game.Objects.GOSeller;
import Game.Objects.GameObject;
import GameMath.GPoint;

/** Spawn Barrels class
 * @author Aikidos
 */
public class SpawnChest extends SpawnerBase {

	@Override
	public void spawn(Level level) throws SlickException {
		if (!level.isUndergroundTown()) {
			for (int i = 0; i < 4; i++) {
				List<GPoint> banCoords = new ArrayList<GPoint>();
				banCoords.add(level.getObjectManager().getPlayer().getCoord());
				banCoords.add(level.getObjectManager().getObjectsByClass(
						"Game.Objects.GOLever")[0].getCoord());
				banCoords.add(level.getObjectManager().getObjectsByClass(
						"Game.Objects.GOTrapdoor")[0].getCoord());

				// Doors
				GameObject[] doors = level.getObjectManager()
						.getObjectsByClass("Game.Objects.GODoor");
				for (GameObject door : doors) {
					banCoords.add(door.getCoord());
				}

				// Keys
				GameObject[] keys = level.getObjectManager().getObjectsByClass(
						"Game.Objects.GODoorKey");
				for (GameObject key : keys) {
					banCoords.add(key.getCoord());
				}

				// Gold Chests
				GameObject[] goldChests = level.getObjectManager()
						.getObjectsByClass("Game.Objects.GOGoldChest");
				for (GameObject goldChest : goldChests) {
					banCoords.add(goldChest.getCoord());
				}

				// Torches
				GameObject[] torches = level.getObjectManager()
						.getObjectsByClass("Game.Objects.GOTorch");
				for (GameObject torch : torches) {
					banCoords.add(torch.getCoord());
				}

				// Barrels
				GameObject[] barrels = level.getObjectManager()
						.getObjectsByClass("Game.Objects.GOBarrel");
				for (GameObject barrel : barrels) {
					banCoords.add(barrel.getCoord());
				}

				// Other chests
				GameObject[] chests = level.getObjectManager()
						.getObjectsByClass("Game.Objects.GOChest");
				for (GameObject chest : chests) {
					banCoords.add(chest.getCoord());
				}

				// Seller
				GameObject[] seller = level.getObjectManager()
						.getObjectsByClass("Game.Objects.GOSeller");
				if (seller.length > 0) {
					banCoords.add(seller[0].getCoord());
				}

				level.getObjectManager().spawnObject(
						new GOChest(level.getObjectManager()), banCoords);
			}
		}
	}
	
}
